<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arrwei = [];
        arrwei.length = 0;
        arrwei['a'] = 123;
        arrwei['b'] = 234;
        console.log(arrwei);
        arrwei = arr(arrwei, 5);

        function arr(obj, i) {
            for (var j = 1; j <= i; j++) {
                obj.length = j;
                obj[j - 1] = j * 2;
            }
            return obj;
        }
        console.log(arrwei);
    </script>
</body>

</html>